#include "game.h"
#include <ctime>
using namespace std;

#include "bitcraziness.h"

int main(int argc, char ** argv)
{
	bitCraziness();

	// initialization
	Game g("map.txt");

	int now, before = clock(), passed;
	bool dirty = true;
	// game loop
	while(g.isRunning())
	{
		// if there is a message to process
		if(kbhit())
		{
			// input
			g.input(getch());
		}
		else
		{
			// timing code
			now = clock();
			passed = now-before;
			before = now;

			Rect r;
			// game logic
			r = g.update(passed);
			if(dirty || r.isValid())
			{
				// draw
				//g.draw(0);
				g.draw(dirty?0:&r);
				dirty = false;
			}

			// throttle code
			while(!kbhit() && clock() < now+10)
			{
				Sleep(1);
			}
		}
	}
	// release
	g.release();
	return 0;
}